home *** CD-ROM | disk | FTP | other *** search
/ Eagles Nest BBS 8 / Eagles_Nest_Mac_Collection_Disc_8.TOAST / Developer Tools⁄Additions / OpenProlog1d / Benchmarks next >
Text File  |  1990-12-16  |  2KB  |  82 lines

  1. nreverse([X|L0],L) :- nreverse(L0,L1),concatenate(L1,[X],L).
  2. nreverse([],[]).
  3.  
  4. concatenate([X|L1],L,[X|L2]) :- concatenate(L1,L,L2).
  5. concatenate([],L,L).
  6.  
  7. list30([1,2,3,4,5,6,7,8,9,10,11,
  8.     12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30]).
  9.  
  10. times10(((((((((x*x)*x)*x)*x)*x)*x)*x)*x)*x).
  11. divide10(((((((((x/x)/x)/x)/x)/x)/x)/x)/x)/x).
  12. log10(log(log(log(log(log(log(log(log(log(log(x))))))))))).
  13. ops8((x+1)*(x^2+2)*(x^3+3)).
  14.  
  15. myRepeat(0,X) :- !.
  16. myRepeat(Count,Procedure) :-
  17.     callAndFail(Procedure),
  18.     NewCount is Count-1,!,
  19.     myRepeat(NewCount,Procedure).
  20.     
  21. dummyRepeat(0,X) :- !.
  22. dummyRepeat(Count,Procedure) :-
  23.     dummyCallAndFail(Procedure),
  24.     NewCount is Count-1,
  25.     !,
  26.     dummyRepeat(NewCount,Procedure).
  27. dummyCallAndFail(X) :- dummyDoOnce(X),fail.
  28. dummyCallAndFail(_).
  29.  
  30. dummyDoOnce(X) :- call(module(X)),!.    %i.e. a do-nothing call
  31.  
  32. callAndFail(X) :- doOnce(X),fail.
  33. callAndFail(_).
  34.  
  35. doOnce(X) :- call(X),!.
  36.  
  37. time(Count,Procedure) :-
  38.     nonvar(Procedure),
  39.     S is cputime,
  40.     myRepeat(Count,Procedure),
  41.     T is cputime,
  42.     dummyRepeat(Count,Procedure),
  43.     Ctime is cputime-T,
  44.     !,
  45.     Etime is T-S,
  46.     Atime is Etime-Ctime,
  47.     telling(CurrentOutput),
  48.     tell(user),
  49.     write('Elapsed time: '),
  50.     write(Atime),write(' mS'),
  51.     tell(CurrentOutput).
  52.  
  53. d(U+V,X,DU+DV) :- !, d(U,X,DU),d(V,X,DV).
  54. d(U-V,X,DU-DV) :- !, d(U,X,DU),d(V,X,DV).
  55. d(U*V,X,DU*V+U*DV) :- !,d(U,X,DU),d(V,X,DV).
  56. d(U/V,X,(DU*V-U*DV)/V^2) :- !,d(U,X,DU),d(V,X,DV).
  57. d(U^N,X,DU*N*U^N1) :- integer(N),N1 is N-1,d(U,X,DU).
  58. d(-U,X,-DU) :- !,d(U,X,DU).
  59. d(exp(U),X,exp(U)*DU) :- !,d(U,X,DU).
  60. d(log(U),X,DU/U) :- !,d(U,X,DU).
  61. d(X,X,1) :- !.
  62. d(C,X,0).
  63.  
  64. list50(
  65. [27,74,17,33,94,18,46,83,65,2,
  66. 32,53,28,85,99,47,28,82,6,11,
  67. 55,29,39,81,90,37,10,0,66,51,
  68. 7,21,85,27,31,63,75,4,95,99,
  69. 11,28,61,74,18,92,40,53,59,8]).
  70.  
  71. qsort([X|L],R,R0) :-
  72.     partition(L,X,L1,L2),
  73.     qsort(L2,R1,R0),
  74.     qsort(L1,R,[X|R1]).
  75. qsort([],R,R).
  76.  
  77. partition([X|L],Y,[X|L1],L2) :- X=<Y,!,
  78.     partition(L,Y,L1,L2).
  79. partition([X|L],Y,L1,[X|L2]) :- 
  80.     partition(L,Y,L1,L2).
  81. partition([],_,[],[]).
  82.